package com.szlanyou.test;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;

import com.szlanyou.lyapplogsave.R;
import com.szlanyou.lyapplogsave.databinding.ActivityMainBinding;

import com.szlanyou.lylog.tool.LyLogSaveTool;

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        requestWritePermissions();
        LyLogSaveTool.getInstance().initAsyn(this);


        findViewById(R.id.btn_write2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LyLogSaveTool.getInstance().writeLogAsyn("日志保存test A a123456789@!");
            }
        });



        findViewById(R.id.btn_write5).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                for (int i = 0; i <= 100; i++) {
                    LyLogSaveTool.getInstance().writeLogAsyn(i+"-压力测试，test A a123456789@!");
                }
            }
        });

    }

    private static final int REQUEST_WRITE_PERMISSION_CODE = 888;

    private void requestWritePermissions() {
        int hasWritePermission = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
        if (hasWritePermission != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_WRITE_PERMISSION_CODE);
        } else {
            LyLog.showLog("permission granted");
        }
    }

}